package com.lyl.novel.controller;

import com.github.pagehelper.PageInfo;
import com.lyl.novel.model.dto.ListNovelDTO;
import com.lyl.novel.model.entity.Novel;
import com.lyl.novel.service.NovelService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author Mr.Luo
 * @date 2022-08-22 16:17
 * @desc 小说管理
 */
@RestController
@RequestMapping("/novel")
@RequiredArgsConstructor
public class NovelController {
    private final NovelService novelService;

    /**
     * 分页查询
     * @param pageNo 页码
     * @param pageSize 页数
     * @param dto dto
     * @return pageInfo
     */
    @PostMapping("/list/{pageNo}/{pageSize}")
    public PageInfo<Novel> list(@PathVariable("pageNo") Integer pageNo,
                                @PathVariable("pageSize") Integer pageSize,
                                @Valid @RequestBody ListNovelDTO dto){
        return novelService.list(pageNo,pageSize,dto);
    }

    /**
     * 获取所有的小说类型
     * @return list
     */
    @GetMapping("/type/list")
    public List<String> type(){
        return novelService.getNovelTypeList();
    }
}
